﻿/********************************************************************************
** 作者： Mick
** 邮箱： zheng_jinfan@126.com
** 主页： http://www.zhengjinfan.cn
** 创始时间：2016-2-4
** 修改人：Mick
** 修改时间：2016-2-5
** 描述：
**      数据库基类接口实现类，…
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq.Expressions;
using NPoco;
using NPoco.Linq;

namespace BestEasyCMS.Core.NPoco
{
    public class DbBase : IDbBase
    {
        private readonly IDatabase _dbBase = DbHelper.CurrentDb;


        #region Basic
        public void OpenSharedConnection()
        {
            _dbBase.OpenSharedConnection();
        }

        public void CloseSharedConnection()
        {
            _dbBase.CloseSharedConnection();
        }

        public int Execute(string sql, params object[] args)
        {
            return _dbBase.Execute(sql, args);
        }

        public int Execute(Sql sql)
        {
            return _dbBase.Execute(sql);
        }

        public T ExecuteScalar<T>(string sql, params object[] args)
        {
            return _dbBase.ExecuteScalar<T>(sql, args);
        }

        public T ExecuteScalar<T>(Sql sql)
        {
            return _dbBase.ExecuteScalar<T>(sql);
        }

        public List<T> Fetch<T>()
        {
            return _dbBase.Fetch<T>();
        }

        public List<T> Fetch<T>(string sql, params object[] args)
        {
            return _dbBase.Fetch<T>(sql, args);
        }

        public List<T> Fetch<T>(Sql sql)
        {
            return _dbBase.Fetch<T>(sql);
        }

        public List<T> Fetch<T>(long page, long itemsPerPage, string sql, params object[] args)
        {
            return _dbBase.Fetch<T>(page, itemsPerPage, sql, args);
        }

        public List<T> Fetch<T>(long page, long itemsPerPage, Sql sql)
        {
            return _dbBase.Fetch<T>(page, itemsPerPage, sql);
        }

        public Page<T> Page<T>(long page, long itemsPerPage, string sql, params object[] args)
        {
            return _dbBase.Page<T>(page, itemsPerPage, sql, args);
        }

        public Page<T> Page<T>(long page, long itemsPerPage, Sql sql)
        {
            return _dbBase.Page<T>(page, itemsPerPage, sql);
        }

        public List<T> SkipTake<T>(long skip, long take, string sql, params object[] args)
        {
            return _dbBase.SkipTake<T>(skip, take, sql, args);
        }

        public List<T> SkipTake<T>(long skip, long take, Sql sql)
        {
            return _dbBase.SkipTake<T>(skip, take, sql);
        }

        public List<TRet> Fetch<T1, T2, TRet>(Func<T1, T2, TRet> cb, string sql, params object[] args)
        {
            return _dbBase.Fetch(cb, sql, args);
        }

        public List<TRet> Fetch<T1, T2, T3, TRet>(Func<T1, T2, T3, TRet> cb, string sql, params object[] args)
        {
            return _dbBase.Fetch(cb, sql, args);
        }

        public List<TRet> Fetch<T1, T2, T3, T4, TRet>(Func<T1, T2, T3, T4, TRet> cb, string sql, params object[] args)
        {
            return _dbBase.Fetch(cb, sql, args);
        }

        public IEnumerable<TRet> Query<T1, T2, TRet>(Func<T1, T2, TRet> cb, string sql, params object[] args)
        {
            return _dbBase.Query(cb, sql, args);
        }

        public IEnumerable<TRet> Query<T1, T2, T3, TRet>(Func<T1, T2, T3, TRet> cb, string sql, params object[] args)
        {
            return _dbBase.Query(cb, sql, args);
        }

        public IEnumerable<TRet> Query<T1, T2, T3, T4, TRet>(Func<T1, T2, T3, T4, TRet> cb, string sql, params object[] args)
        {
            return _dbBase.Query(cb, sql, args);
        }

        public Page<TRet> Page<T1, T2, TRet>(Func<T1, T2, TRet> cb, long page, long itemsPerPage, string sql, params object[] args)
        {
            return _dbBase.Page(cb, page, itemsPerPage, sql, args);
        }

        public Page<TRet> Page<T1, T2, T3, TRet>(Func<T1, T2, T3, TRet> cb, long page, long itemsPerPage, string sql, params object[] args)
        {
            return _dbBase.Page(cb, page, itemsPerPage, sql, args);
        }

        public Page<TRet> Page<T1, T2, T3, T4, TRet>(Func<T1, T2, T3, T4, TRet> cb, long page, long itemsPerPage, string sql, params object[] args)
        {
            return _dbBase.Page(cb, page, itemsPerPage, sql, args);
        }

        public List<TRet> Fetch<T1, T2, TRet>(Func<T1, T2, TRet> cb, Sql sql)
        {
            return _dbBase.Fetch(cb, sql);
        }

        public List<TRet> Fetch<T1, T2, T3, TRet>(Func<T1, T2, T3, TRet> cb, Sql sql)
        {
            return _dbBase.Fetch(cb, sql);
        }

        public List<TRet> Fetch<T1, T2, T3, T4, TRet>(Func<T1, T2, T3, T4, TRet> cb, Sql sql)
        {
            return _dbBase.Fetch(cb, sql);
        }

        public IEnumerable<TRet> Query<T1, T2, TRet>(Func<T1, T2, TRet> cb, Sql sql)
        {
            return _dbBase.Query(cb, sql);
        }

        public IEnumerable<TRet> Query<T1, T2, T3, TRet>(Func<T1, T2, T3, TRet> cb, Sql sql)
        {
            return _dbBase.Query(cb, sql);
        }

        public IEnumerable<TRet> Query<T1, T2, T3, T4, TRet>(Func<T1, T2, T3, T4, TRet> cb, Sql sql)
        {
            return _dbBase.Query(cb, sql);
        }

        public Page<TRet> Page<T1, T2, TRet>(Func<T1, T2, TRet> cb, long page, long itemsPerPage, Sql sql)
        {
            return _dbBase.Page(cb, page, itemsPerPage, sql);
        }

        public Page<TRet> Page<T1, T2, T3, TRet>(Func<T1, T2, T3, TRet> cb, long page, long itemsPerPage, Sql sql)
        {
            return _dbBase.Page(cb, page, itemsPerPage, sql);
        }

        public Page<TRet> Page<T1, T2, T3, T4, TRet>(Func<T1, T2, T3, T4, TRet> cb, long page, long itemsPerPage, Sql sql)
        {
            return _dbBase.Page(cb, page, itemsPerPage, sql);
        }

        public List<T1> Fetch<T1, T2>(string sql, params object[] args)
        {
            return _dbBase.Fetch<T1, T2>(sql, args);
        }

        public List<T1> Fetch<T1, T2, T3>(string sql, params object[] args)
        {
            return _dbBase.Fetch<T1, T2, T3>(sql, args);
        }

        public List<T1> Fetch<T1, T2, T3, T4>(string sql, params object[] args)
        {
            return _dbBase.Fetch<T1, T2, T3, T4>(sql, args);
        }

        public IEnumerable<T1> Query<T1, T2>(string sql, params object[] args)
        {
            return _dbBase.Query<T1, T2>(sql, args);
        }

        public IEnumerable<T1> Query<T1, T2, T3>(string sql, params object[] args)
        {
            return _dbBase.Query<T1, T2, T3>(sql, args);
        }

        public IEnumerable<T1> Query<T1, T2, T3, T4>(string sql, params object[] args)
        {
            return _dbBase.Query<T1, T2, T3, T4>(sql, args);
        }

        public Page<T1> Page<T1, T2>(long page, long itemsPerPage, string sql, params object[] args)
        {
            return _dbBase.Page<T1, T2>(page, itemsPerPage, sql, args);
        }

        public Page<T1> Page<T1, T2, T3>(long page, long itemsPerPage, string sql, params object[] args)
        {
            return _dbBase.Page<T1, T2, T3>(page, itemsPerPage, sql, args);
        }

        public Page<T1> Page<T1, T2, T3, T4>(long page, long itemsPerPage, string sql, params object[] args)
        {
            return _dbBase.Page<T1, T2, T3, T4>(page, itemsPerPage, sql, args);
        }

        public IEnumerable<TRet> Query<TRet>(Type[] types, Delegate cb, Sql sql)
        {
            return _dbBase.Query<TRet>(types, cb, sql);
        }

        public Page<TRet> Page<TRet>(Type[] types, Delegate cb, long page, long itemsPerPage, string sql, params object[] args)
        {
            return _dbBase.Page<TRet>(types, cb, page, itemsPerPage, sql, args);
        }

        public List<T1> Fetch<T1, T2>(Sql sql)
        {
            return _dbBase.Fetch<T1, T2>(sql);
        }

        public List<T1> Fetch<T1, T2, T3>(Sql sql)
        {
            return _dbBase.Fetch<T1, T2, T3>(sql);
        }

        public List<T1> Fetch<T1, T2, T3, T4>(Sql sql)
        {
            return _dbBase.Fetch<T1, T2, T3, T4>(sql);
        }

        public IEnumerable<T1> Query<T1, T2>(Sql sql)
        {
            return _dbBase.Query<T1, T2>(sql);
        }

        public IEnumerable<T1> Query<T1, T2, T3>(Sql sql)
        {
            return _dbBase.Query<T1, T2, T3>(sql);
        }

        public IEnumerable<T1> Query<T1, T2, T3, T4>(Sql sql)
        {
            return _dbBase.Query<T1, T2, T3, T4>(sql);
        }

        public Page<T1> Page<T1, T2>(long page, long itemsPerpage, Sql sql)
        {
            return _dbBase.Page<T1, T2>(page, itemsPerpage, sql);
        }

        public Page<T1> Page<T1, T2, T3>(long page, long itemsPerpage, Sql sql)
        {
            return _dbBase.Page<T1, T2, T3>(page, itemsPerpage, sql);
        }

        public Page<T1> Page<T1, T2, T3, T4>(long page, long itemsPerpage, Sql sql)
        {
            return _dbBase.Page<T1, T2, T3, T4>(page, itemsPerpage, sql);
        }

        public IEnumerable<T> Query<T>(string sql, params object[] args)
        {
            return _dbBase.Query<T>(sql, args);
        }

        public IEnumerable<T> Query<T>(Sql sql)
        {
            return _dbBase.Query<T>(sql);
        }

        public IQueryProviderWithIncludes<T> Query<T>()
        {
            return _dbBase.Query<T>();
        }

        public T SingleById<T>(object primaryKey)
        {
            return _dbBase.SingleById<T>(primaryKey);
        }

        public T SingleOrDefaultById<T>(object primaryKey)
        {
            return _dbBase.SingleOrDefaultById<T>(primaryKey);
        }

        public T Single<T>(string sql, params object[] args)
        {
            return _dbBase.Single<T>(sql, args);
        }

        public T SingleInto<T>(T instance, string sql, params object[] args)
        {
            return _dbBase.SingleInto(instance, sql, args);
        }

        public T SingleOrDefault<T>(string sql, params object[] args)
        {
            return _dbBase.SingleOrDefault<T>(sql, args);
        }

        public T SingleOrDefaultInto<T>(T instance, string sql, params object[] args)
        {
            return _dbBase.SingleOrDefaultInto(instance, sql, args);
        }

        public T First<T>(string sql, params object[] args)
        {
            return _dbBase.First<T>(sql, args);
        }

        public T FirstInto<T>(T instance, string sql, params object[] args)
        {
            return _dbBase.FirstInto(instance, sql, args);
        }

        public T FirstOrDefault<T>(string sql, params object[] args)
        {
            return _dbBase.FirstOrDefault<T>(sql, args);
        }

        public T FirstOrDefaultInto<T>(T instance, string sql, params object[] args)
        {
            return _dbBase.FirstOrDefaultInto(instance, sql, args);
        }

        public T Single<T>(Sql sql)
        {
            return _dbBase.Single<T>(sql);
        }

        public T SingleInto<T>(T instance, Sql sql)
        {
            return _dbBase.SingleInto(instance, sql);
        }

        public T SingleOrDefault<T>(Sql sql)
        {
            return _dbBase.SingleOrDefault<T>(sql);
        }

        public T SingleOrDefaultInto<T>(T instance, Sql sql)
        {
            return _dbBase.SingleOrDefaultInto(instance, sql);
        }

        public T First<T>(Sql sql)
        {
            return _dbBase.First<T>(sql);
        }

        public T FirstInto<T>(T instance, Sql sql)
        {
            return _dbBase.FirstInto(instance, sql);
        }

        public T FirstOrDefault<T>(Sql sql)
        {
            return _dbBase.FirstOrDefault<T>(sql);
        }

        public T FirstOrDefaultInto<T>(T instance, Sql sql)
        {
            return _dbBase.FirstOrDefaultInto(instance, sql);
        }

        public Dictionary<TKey, TValue> Dictionary<TKey, TValue>(Sql sql)
        {
            return _dbBase.Dictionary<TKey, TValue>(sql);
        }

        public Dictionary<TKey, TValue> Dictionary<TKey, TValue>(string sql, params object[] args)
        {
            return _dbBase.Dictionary<TKey, TValue>(sql, args);
        }

        public bool Exists<T>(object primaryKey)
        {
            return _dbBase.Exists<T>(primaryKey);
        }

        public TRet FetchMultiple<T1, T2, TRet>(Func<List<T1>, List<T2>, TRet> cb, string sql, params object[] args)
        {
            return _dbBase.FetchMultiple(cb, sql, args);
        }

        public TRet FetchMultiple<T1, T2, T3, TRet>(Func<List<T1>, List<T2>, List<T3>, TRet> cb, string sql, params object[] args)
        {
            return _dbBase.FetchMultiple(cb, sql, args);
        }

        public TRet FetchMultiple<T1, T2, T3, T4, TRet>(Func<List<T1>, List<T2>, List<T3>, List<T4>, TRet> cb, string sql, params object[] args)
        {
            return _dbBase.FetchMultiple(cb, sql, args);
        }

        public TRet FetchMultiple<T1, T2, TRet>(Func<List<T1>, List<T2>, TRet> cb, Sql sql)
        {
            return _dbBase.FetchMultiple(cb, sql);
        }

        public TRet FetchMultiple<T1, T2, T3, TRet>(Func<List<T1>, List<T2>, List<T3>, TRet> cb, Sql sql)
        {
            return _dbBase.FetchMultiple(cb, sql);
        }

        public TRet FetchMultiple<T1, T2, T3, T4, TRet>(Func<List<T1>, List<T2>, List<T3>, List<T4>, TRet> cb, Sql sql)
        {
            return _dbBase.FetchMultiple(cb, sql);
        }

        public Tuple<List<T1>, List<T2>> FetchMultiple<T1, T2>(string sql, params object[] args)
        {
            return _dbBase.FetchMultiple<T1, T2>(sql, args);
        }

        public Tuple<List<T1>, List<T2>, List<T3>> FetchMultiple<T1, T2, T3>(string sql, params object[] args)
        {
            return _dbBase.FetchMultiple<T1, T2, T3>(sql, args);
        }

        public Tuple<List<T1>, List<T2>, List<T3>, List<T4>> FetchMultiple<T1, T2, T3, T4>(string sql, params object[] args)
        {
            return _dbBase.FetchMultiple<T1, T2, T3, T4>(sql, args);
        }

        public Tuple<List<T1>, List<T2>> FetchMultiple<T1, T2>(Sql sql)
        {
            return _dbBase.FetchMultiple<T1, T2>(sql);
        }

        public Tuple<List<T1>, List<T2>, List<T3>> FetchMultiple<T1, T2, T3>(Sql sql)
        {
            return _dbBase.FetchMultiple<T1, T2, T3>(sql);
        }

        public Tuple<List<T1>, List<T2>, List<T3>, List<T4>> FetchMultiple<T1, T2, T3, T4>(Sql sql)
        {
            return _dbBase.FetchMultiple<T1, T2, T3, T4>(sql);
        }

        public IDataParameter CreateParameter()
        {
            return _dbBase.CreateParameter();
        }

        public void AddParameter(IDbCommand cmd, object value)
        {
            _dbBase.AddParameter(cmd, value);
        }

        public IDbCommand CreateCommand(IDbConnection connection, string sql, params object[] args)
        {
            return _dbBase.CreateCommand(connection, sql, args);
        }

        public ITransaction GetTransaction()
        {
            return _dbBase.GetTransaction();
        }

        public ITransaction GetTransaction(IsolationLevel isolationLevel)
        {
            return _dbBase.GetTransaction(isolationLevel);
        }

        public void SetTransaction(IDbTransaction tran)
        {
            _dbBase.SetTransaction(tran);
        }

        public void BeginTransaction()
        {
            _dbBase.BeginTransaction();
        }

        public void BeginTransaction(IsolationLevel isolationLevel)
        {
            _dbBase.BeginTransaction(isolationLevel);
        }

        public void AbortTransaction()
        {
            _dbBase.AbortTransaction();
        }

        public void CompleteTransaction()
        {
            _dbBase.CompleteTransaction();
        }

        public object Insert<T>(string tableName, string primaryKeyName, bool autoIncrement, T poco)
        {
            return _dbBase.Insert(tableName, primaryKeyName, autoIncrement, poco);
        }

        public object Insert<T>(string tableName, string primaryKeyName, T poco)
        {
            return _dbBase.Insert(tableName, primaryKeyName, poco);
        }

        public object Insert<T>(T poco)
        {
            return _dbBase.Insert(poco);
        }

        public void InsertBulk<T>(IEnumerable<T> pocos)
        {
            _dbBase.InsertBulk(pocos);
        }

        public int Update(string tableName, string primaryKeyName, object poco, object primaryKeyValue)
        {
            return _dbBase.Update(tableName, primaryKeyName, poco, primaryKeyValue);
        }

        public int Update(string tableName, string primaryKeyName, object poco)
        {
            return _dbBase.Update(tableName, primaryKeyName, poco);
        }

        public int Update(string tableName, string primaryKeyName, object poco, object primaryKeyValue, IEnumerable<string> columns)
        {
            return _dbBase.Update(tableName, primaryKeyName, poco, primaryKeyValue, columns);
        }

        public int Update(string tableName, string primaryKeyName, object poco, IEnumerable<string> columns)
        {
            return _dbBase.Update(tableName, primaryKeyName, poco, columns);
        }

        public int Update(object poco, IEnumerable<string> columns)
        {
            return _dbBase.Update(poco, columns);
        }

        public int Update(object poco, object primaryKeyValue, IEnumerable<string> columns)
        {
            return _dbBase.Update(poco, primaryKeyValue, columns);
        }

        public int Update(object poco)
        {
            return _dbBase.Update(poco);
        }

        public int Update<T>(T poco, Expression<Func<T, object>> fields)
        {
            return _dbBase.Update(poco, fields);
        }

        public int Update(object poco, object primaryKeyValue)
        {
            return _dbBase.Update(poco, primaryKeyValue);
        }

        public int Update<T>(string sql, params object[] args)
        {
            return _dbBase.Update<T>(sql, args);
        }

        public int Update<T>(Sql sql)
        {
            return _dbBase.Update<T>(sql);
        }

        public IUpdateQueryProvider<T> UpdateMany<T>()
        {
            return _dbBase.UpdateMany<T>();
        }

        public int Delete(string tableName, string primaryKeyName, object poco)
        {
            return _dbBase.Delete(tableName, primaryKeyName, poco);
        }

        public int Delete(string tableName, string primaryKeyName, object poco, object primaryKeyValue)
        {
            return _dbBase.Delete(tableName, primaryKeyName, poco, primaryKeyValue);
        }

        public int Delete(object poco)
        {
            return _dbBase.Delete(poco);
        }

        public int Delete<T>(string sql, params object[] args)
        {
            return _dbBase.Delete<T>(sql, args);
        }

        public int Delete<T>(Sql sql)
        {
            return _dbBase.Delete<T>(sql);
        }

        public int Delete<T>(object pocoOrPrimaryKey)
        {
            return _dbBase.Delete<T>(pocoOrPrimaryKey);
        }

        public IDeleteQueryProvider<T> DeleteMany<T>()
        {
            return _dbBase.DeleteMany<T>();
        }

        public void Save<T>(object poco)
        {
            _dbBase.Save<T>(poco);
        }

        public bool IsNew<T>(object poco)
        {
            return _dbBase.IsNew<T>(poco);
        }
        #endregion 

        #region Ext

        public IEnumerable<T> ExecuteProcedure<T>(SqlCommand sqlCmd,IEnumerable<SqlParameter> sqlParams)
        {
            return _dbBase.ExecuteProcedure<T>(sqlCmd, sqlParams);
        }


        #region Private Method

        

        #endregion
        #endregion
    }
}
